<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-input v-model="search.name" placeholder="名称" clearable></el-input>
                    <el-select v-model="search.auditStatus" placeholder="审核状态" clearable>
                        <el-option label="待审核" :value="0"></el-option>
                        <el-option label="审核通过" :value="1"></el-option>
                        <el-option label="审核被拒" :value="2"></el-option>
                    </el-select>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-plus" @click="table_add">申请</el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.agentPartnerAudit.list" remoteSort :params="search" @selection-change="selectionChange" @dataChange="dataChange">
                    <el-table-column label="机构" prop="name" align="left" >
                        <template #default="scope">
                            {{ scope.row.agent ? scope.row.agent.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="申请数量" prop="number" width="130" align="center"></el-table-column>
                    <el-table-column label="状态" prop="auditStatus" width="110" align="center">
                        <template #default="scope">
                            <el-tag size="mini" v-if="scope.row.status.value == 0" type="warning">{{scope.row.status.name}}</el-tag>
                            <el-tag size="mini" v-if="scope.row.status.value == 1" type="success">{{scope.row.status.name}}</el-tag>
                            <el-tag size="mini" v-if="scope.row.status.value == 2" type="danger">{{scope.row.status.name}}</el-tag>
                            <template v-if="scope.row.status.value == 2">
									<el-tooltip class="box-item" effect="dark" :content="scope.row.statusRemarks" placement="top-end">
										<i style="cursor: pointer" class="el-icon-question table-msg" />
									</el-tooltip>
							</template>
                        </template>
                    </el-table-column>
                    <el-table-column label="申请时间" prop="createdAt" width="150" align="center"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="200">
                        <template #default="scope">
                            <el-popconfirm :title="'确认是否要删除该申请？'" @confirm="table_del(scope.row)">
                                <template #reference>
                                    <el-button type="text" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>

    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
import saveDialog from './save'
export default {
    components: {
        saveDialog
    },
    data() {
        return {
            dialog: {
                save: false,
            },
            selection: [],
            search: {
                name: null,
            }
        }
    },
    mounted() {
        
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = total - (page * perPage + index - perPage)
            })
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        // 增加
        table_add() {
            this.dialog.save = true
            this.$nextTick(() => {
                this.$refs.saveDialog.open()
            })
        },
        //删除
        async table_del(row) {
            await this.$API.agentPartnerAudit.action.delete({ id: row.id }).then(() => {
                this.$notify.success("删除成功")
                this.$refs.table.refresh()
            })
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selection = selection;
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
</style>
